package net.zjitc.call;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Random;

/**
 * @Author: Administrator
 * @Date: 2020/5/21 18:22
 * 随机点名
 */
@WebServlet("/randomCall2")
public class RandomCall2 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Object yd_list = req.getSession().getAttribute("yd_list");
        String[] yd= (String[]) yd_list;
        Random ran = new Random();
        // 根据数组长度，获取随机索引，[0,length)
        int randomIndex = ran.nextInt(yd.length);
        String name = yd[randomIndex];

        req.getSession().setAttribute("name",name);
       resp.sendRedirect("/web/randomCall");

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
